'use client';

// 批量导入组件
// REF: API-SHARE189-004@v1.0

import React, { useState } from 'react';
import { Upload } from 'lucide-react';

import { Button } from '@/components/ui/button';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { Textarea } from '@/components/ui/textarea';
import { useToast } from '@/hooks/use-toast';

import { BatchImportProps } from './types';

export function BatchImport({ onImport }: BatchImportProps) {
  const { toast } = useToast();
  const [importText, setImportText] = useState('');

  const handleImport = async () => {
    if (!importText.trim()) {
      toast({
        title: '请输入内容',
        description: '导入内容不能为空',
        variant: 'destructive'
      });
      return;
    }
    
    await onImport(importText);
    setImportText('');
  };

  return (
    <Card>
      <CardHeader>
        <CardTitle className="flex items-center gap-2">
          <Upload className="h-5 w-5" />
          批量导入
        </CardTitle>
      </CardHeader>
      <CardContent className="space-y-4">
        <Textarea
          placeholder="粘贴包含分享链接的文本，系统会自动识别分享码和访问码"
          value={importText}
          onChange={(e) => setImportText(e.target.value)}
          rows={6}
        />
        <Button onClick={handleImport} className="w-full">
          <Upload className="h-4 w-4 mr-2" />
          导入分享码
        </Button>
      </CardContent>
    </Card>
  );
}

export default BatchImport;